import { createActions, handleActions } from 'redux-actions';
import SocketIO from '@socket-io';

const initState = {
  socketIO: null
};

export const actions = createActions({
  INIT: options => new SocketIO(options)
});

const reducer = handleActions(
  {
    INIT: (state, action) => {
      const { error, payload } = action;
      if (!error) {
        return {
          ...state,
          socketIO: payload
        };
      }
    }
  },
  initState
);

export default reducer;
